package cn.autumnorange.app.common.dto;

import com.fasterxml.jackson.annotation.JsonInclude;

import java.util.Date;

/**
 * Copyright © 2018 eSunny Info. Tech Ltd. All rights reserved.
 *
 * @title: ResultDto.java @Package: com.yulece.common.utils
 * @author: wangyichao@yulece.com
 * @date: 创建时间2018年5月1日 - 下午4:48:02
 * @version: 1.0
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResultDto<T> {

  private String message;
  private T data;
  private String path;
  private Date date = new Date();

  public ResultDto() {}

  public ResultDto(T data, String message, String path, Date date) {
    this.message = message;
    this.data = data;
    this.path = path;
    if (date != null) {
      this.date = date;
    }
  }

  public String getPath() {
    return path;
  }

  public void setPath(String path) {
    this.path = path;
  }

  public Date getDate() {
    return date;
  }

  public void setDate(Date date) {
    this.date = date;
  }

  public String getMessage() {
    return message;
  }

  public void setMessage(String message) {
    this.message = message;
  }

  public T getData() {
    return data;
  }

  public void setData(T data) {
    this.data = data;
  }

  @SuppressWarnings({"unchecked", "rawtypes"})
  public static <T> ResultDto<T> createResult() {
    return new ResultDto();
  }

  @SuppressWarnings({"unchecked", "rawtypes"})
  public static <T> ResultDto<T> createResult(T data, String message, String path, Date date) {
    return new ResultDto(data, message, path, date);
  }

  @SuppressWarnings({"unchecked", "rawtypes"})
  public static <T> ResultDto<T> createDataResult(T data) {
    return createResult(data, null, null, null);
  }

  @SuppressWarnings({"unchecked", "rawtypes"})
  public static <T> ResultDto<T> createMessageResult(String message) {
    return createResult(null, message, null, null);
  }

  @SuppressWarnings({"unchecked", "rawtypes"})
  public static <T> ResultDto<T> createPathResult(String path) {
    return createResult(null, path, null, null);
  }

  @SuppressWarnings({"unchecked", "rawtypes"})
  public static <T> ResultDto<T> createDataMessageResult(T data, String message) {
    return createResult(data, message, null, null);
  }

  @SuppressWarnings({"unchecked", "rawtypes"})
  public static <T> ResultDto<T> createDataMessagePathResult(T data, String message, String path) {
    return createResult(data, message, path, null);
  }
}
